package com.bw.gmall.api.repository;

import com.bw.gmall.api.model.UserProfileStats;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class UserProfileStatsRepository {
/*
UserProfileStatsRepository：用户画像统计数据访问类，
提供查询用户画像数据的方法，操作表dws_user_profile_stats_window。
* */
    @Autowired
    private JdbcTemplate jdbcTemplate;

    public List<UserProfileStats> findAll() {
        String sql = "SELECT * FROM dws_user_profile_stats_window ORDER BY stats_time DESC LIMIT 100";
        return jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(UserProfileStats.class));
    }

    public List<UserProfileStats> findByTimeRange(String startTime, String endTime) {
        String sql = "SELECT * FROM dws_user_profile_stats_window WHERE stats_time BETWEEN ? AND ? ORDER BY stats_time";
        return jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(UserProfileStats.class), startTime, endTime);
    }
}